<template>
  <div>
    <h2>
      user组件
      <a-button @click="test">点击</a-button>
    </h2>
  </div>
</template>
<script setup lang="ts">
import { UserControllerService } from "../../generated";
import { useUserStore } from "@/store/UserStore";
import { Message } from "@arco-design/web-vue";
import { ref } from "vue";

let loginData = {
  userAccount: "test",
  userPassword: "12345678",
};

let test = async () => {
  let res = await UserControllerService.userLoginUsingPost(loginData);
  if (res.code === 0) {
    // 检查响应头中是否有Set-Cookie
    // const setCookieHeader = res.headers["Set-cookie"];
    // console.log("Set-cookie:", setCookieHeader);
    // if (setCookieHeader) {
    //   // 解析Set-Cookie头部，这里简化处理，实际应用可能需要更复杂的解析
    //   const sessionId = setCookieHeader[0].split(";")[0].split("=")[1];
    //   // 将sessionId保存到本地存储或cookie
    //   document.cookie = `sessionId=${sessionId}`;
    // }

    const userStore = ref(useUserStore());
    userStore.value.loginUser = res.data;
    console.log(userStore.value.loginUser);
    console.log(useUserStore().loginUser);
    Message.success("登录成功");
  } else {
    Message.error(res.message);
  }
};
</script>
<style scoped></style>
